package com.wutianyi.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.wutianyi.task.Tasks;
import com.wutianyi.utils.NetUtils;

public class TasksServlet extends HttpServlet
{

    /**
     * 
     */
    private static final long serialVersionUID = 8095544649911535482L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        String className = NetUtils.getParameterString(req, "className", null);
        PrintWriter pw = resp.getWriter();

        if (StringUtils.isBlank(className))
        {
            pw.print(0);
            return;
        }

        Tasks task = null;
        try
        {
            task = (Tasks) this.getClass().getClassLoader().loadClass(className).newInstance();
            task.run(req);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            pw.print(0);
            return;
        }
        pw.print(1);
    }

}
